/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uit.ieproject.presentation;

import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JTextPane;
import uit.ieproject.crawler.MyControllerThread;

/**
 *
 * @author RedDevils
 */
public class ProgressDownloadFrame extends javax.swing.JFrame {

    public static JProgressBar pbStatus;
    public static JTextPane tpStatus;

    /**
     * Creates new form ProgressDownloadFrame
     */
    public ProgressDownloadFrame() {
        initComponents();
        pbStatus = pbCurrentStatus;
        tpStatus = tpCurrentStatus;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        pbCurrentStatus = new javax.swing.JProgressBar();
        jScrollPane2 = new javax.swing.JScrollPane();
        tpCurrentStatus = new javax.swing.JTextPane();

        jScrollPane1.setViewportView(jTextPane1);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        pbCurrentStatus.setEnabled(false);

        tpCurrentStatus.setEditable(false);
        jScrollPane2.setViewportView(tpCurrentStatus);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pbCurrentStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(pbCurrentStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        if ((MainFrame.crawlerThread != null && MainFrame.crawlerThread.isAlive())) {
            String warning = "";
            if (MainFrame.crawlerThread != null && MainFrame.crawlerThread.isAlive()) {
                warning = "Tiến trình tải tập tin vẫn chưa kết thúc! Bạn có muốn thoát?";
            }
            int select = JOptionPane.showConfirmDialog(null, warning, "Chú ý", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null);
            if (select == JOptionPane.YES_OPTION) {
                this.dispose();
                MyControllerThread.controller.Shutdown();
                MyControllerThread.controller.waitUntilFinish();
                MainFrame.downloadNameButton.setEnabled(true);
            }
        } else {
            this.dispose();
            MyControllerThread.controller.Shutdown();
            MyControllerThread.controller.waitUntilFinish();
            MainFrame.downloadNameButton.setEnabled(true);
        }
    }//GEN-LAST:event_formWindowClosing
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JProgressBar pbCurrentStatus;
    private javax.swing.JTextPane tpCurrentStatus;
    // End of variables declaration//GEN-END:variables
}
